home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / ARASAN_S.ZIP / PIECE.H < prev    next >
C/C++ Source or Header  |  1994-06-16  |  2KB  |  96 lines

  1. // Copyright 1992 by Jon Dart.  All Rights Reserved.
  2. #ifndef _PIECE_H
  3. #define _PIECE_H
  4.  
  5. #include "types.h"
  6. #include "color.h"
  7.  
  8. class Piece {
  9.    public:
  10.        
  11.    enum PieceType { Empty, Pawn, Knight, Bishop, Rook, Queen, King, Invalid };
  12.  
  13.    Piece()
  14.    {
  15.        my_piece = Empty;
  16.    }
  17.    
  18.    Piece(  const PieceType type, const ColorType color )
  19.    {
  20.       if (color == White)
  21.          my_piece = 8 | type;
  22.       else 
  23.          my_piece = type;
  24.    }
  25.    
  26.    Piece( const Piece &p )
  27.    {
  28.         my_piece = p.my_piece;
  29.    }
  30.    
  31.    ~Piece()
  32.    {
  33.    }
  34.    
  35.    operator int() const
  36.    {
  37.        return my_piece;
  38.    }
  39.     
  40.    const PieceType Type() const
  41.    {
  42.        return (PieceType)(my_piece & 7);
  43.    }
  44.    
  45.    const Boolean sliding() const;
  46.    
  47.    const ColorType Color() const
  48.    {
  49.        return (my_piece & 8) ? White : Black;
  50.    }
  51.    
  52.    static const Piece &EmptyPiece();
  53.  
  54.    static const Piece &InvalidPiece();
  55.    
  56.    const int operator == ( const Piece &p) const
  57.    {
  58.        return p.my_piece == my_piece;
  59.    }
  60.    
  61.    Boolean IsEmpty() const
  62.    {
  63.     return Boolean(Type() == Empty);   
  64.    }
  65.    
  66.    unsigned Value() const;
  67.    // value of the piece
  68.        
  69.    static unsigned Value( PieceType type);
  70.    // value of a piece
  71.        
  72.    static Piece::PieceType Value( const char );
  73.    // Convert a character representation of a piece into a PieceType.
  74.    // Inverse of Image function, below.
  75.        
  76.    static char Image(const Piece::PieceType p);
  77.    // 1-character representation of piece
  78.        
  79.    protected:
  80.        
  81.    Piece( PieceType type );
  82.    
  83.    byte internal_value() const
  84.    {
  85.        return my_piece;
  86.    }
  87.    
  88.    private:
  89.        
  90.    byte my_piece;       
  91. };
  92.  
  93. #endif
  94.  
  95.  
  96.